<script lang="ts" setup>
import type { ConfigProviderThemeVars } from 'wot-design-uni'
import FgTabbar from './fg-tabbar/fg-tabbar.vue'
import { useIm } from '@/hooks/useIm'
import * as authUtil from '@/utils/auth'
// import { useLocationChange } from '@/hooks/useLocationChange'

const imCube = useIm()
const themeVars: ConfigProviderThemeVars = {
  // colorTheme: 'red',
  // buttonPrimaryBgColor: '#07c160',
  // buttonPrimaryColor: '#07c160',
}
// 获取屏幕边界到安全区域距离
const systemInfo = uni.getWindowInfo()
const safeAreaInsets = systemInfo.safeAreaInsets || {
  top: 0,
  right: 0,
  bottom: 0,
  left: 0,
}
// const { currentLocation, startListen, stopListen } = useLocationChange(
//   (location) => {
//     console.log('位置变化:', location)
//     // 在这里处理位置变化逻辑
//   },
//   {
//     throttleTime: 2000, // 2秒节流
//     highAccuracy: true // 使用高精度定位
//   }
// )
// onLoad(() => {
//   console.log('初始位置:', currentLocation.value)
//   startListen()
// })

onShow(() => {
  if (!authUtil.getAccessToken()) {
    uni.redirectTo({
      url: '/pages/login/login',
    })
  }else{
    imCube.init()
  }
})
</script>

<template>
  <wd-config-provider :theme-vars="themeVars">
    <view
      class="pageView"
      :style="{
        '--minus-top': `${safeAreaInsets.top}px`,
        '--minus-bottom': `${safeAreaInsets.bottom}px`,
      }"
    >
      <slot />
    </view>
    <FgTabbar />
    <wd-toast />
    <wd-message-box />
  </wd-config-provider>
</template>

<style lang="scss" scoped>
.pageView {
  height: calc(100vh - var(--minus-top) - var(--minus-bottom) - 50px);
  margin-top: var(--minus-top);
  // background-color: var(--page-bg-color);
}
</style>
